package com.zmn.plat.services.impl.service.itemdetail;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.service.itemdetail.ItemDetail;
import com.zmn.plat.model.entity.service.itemdetail.ItemDetailQuery;
import com.zmn.plat.persistence.interfaces.service.itemdetail.ItemDetailDao;
import com.zmn.plat.services.interfaces.service.itemdetail.ItemDetailService;
import org.springframework.util.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import com.zmn.common.constant.GlobalConsts;

/**
 * 描述: 项目明细-计价器3.0接口实现类
 *
 * @author guoqiao
 * @since  2021/11/19 15:02
 */
@Slf4j
@Service
public class ItemDetailServiceImpl implements ItemDetailService {

    private static final String TAG = "项目明细-计价器3.0基础服务接口";

    @Resource
    private ItemDetailDao itemDetailDao;

    @Override
    public ItemDetail findById(Integer itemId) {
        if (Objects.isNull(itemId)) {
            log.error("[{}],根据id查询数据itemId为null", TAG);
            return null;
        }
        return itemDetailDao.findById(itemId);
    }

    @Override
    public List<ItemDetail> listByIds(List<Integer> itemIds) {
        if (CollectionUtils.isEmpty(itemIds)) {
            log.error("[{}],按条件查询数据,itemIds为null", TAG);
            return null;
        }
        return itemDetailDao.listByIds(itemIds);
    }

    @Override
    public List<ItemDetail> listByQuery(ItemDetailQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return itemDetailDao.listByQuery(query);
    }

    @Override
    public List<ItemDetail> listPageByQuery(ItemDetailQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(itemDetailDao.countByQuery(query));
        return itemDetailDao.listPageByQuery(query);
    }

    @Override
    public Integer countByQuery(ItemDetailQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return itemDetailDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(ItemDetail itemDetail) {
        if (Objects.isNull(itemDetail.getItemId())){
            log.error("[{}],根据id修改数据,itemDetail为null", TAG);
            return null;
        }
        return itemDetailDao.updateByKey(itemDetail);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {
        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        itemDetailDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert(ItemDetail itemDetail){
        if (Objects.isNull(itemDetail)){
            log.error("[{}],新增数据,itemDetail为null", TAG);
            return null;
        }
        return itemDetailDao.insert(itemDetail);
    }

    @Override
    public void insertBatch(List<ItemDetail> list){
        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        itemDetailDao.insertBatch(list);
    }

    @Override
    public Integer deleteByKey(Integer itemId) {
        if (Objects.isNull(itemId)){
            log.error("[{}],根据id删除数据,itemId为null", TAG);
            return null;
        }
        return itemDetailDao.deleteByKey(itemId);
    }

}